package cn.micai.base.task;

import java.math.BigInteger;
import java.util.List;

import static java.util.concurrent.TimeUnit.SECONDS;

/**
 * @Auther: zhaoxinguo
 * @Date: 2018/7/16 11:04
 * @Description: 让素数生成器运行1秒钟就取消
 */
public class PrimeGeneratorTest {

    public static List<BigInteger> aSecondOfPrimes() {
        PrimeGenerator primeGenerator = new PrimeGenerator();
        new Thread(primeGenerator).start();
        try {
            SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            primeGenerator.cancel();
        }
        return primeGenerator.get();
    }

    public static void main(String [] args) {
        List<BigInteger> primes = aSecondOfPrimes();
        primes.stream().forEach(System.out::println);
    }
}
